package com.atguigu.srb.core.controller.admin;

import com.atguigu.common.result.R;
import com.atguigu.srb.core.pojo.entity.UserInfo;
import com.atguigu.srb.core.pojo.query.UserInfoQuery;
import com.atguigu.srb.core.service.UserInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lupengning
 * @version 1.0
 * @description:
 * @date 2021/6/8 17:16
 */
@Api(tags = "会员管理")
@RestController
@RequestMapping("/admin/core/userInfo")
@Slf4j
//@CrossOrigin
public class AdminUserInfoController {

  @Resource
  private UserInfoService userInfoService;

  @GetMapping("list/{page}/{limit}")
  @ApiOperation("获取会员分页列表")
  public R listPage(
      @ApiParam(value = "当前页码", required = true) @PathVariable Long page,
      @ApiParam(value = "每页记录数", required = true) @PathVariable Long limit,
      @ApiParam(value = "查询对象", required = false) UserInfoQuery userInfoQuery) {
    Page<UserInfo> pageParam = new Page<>(page, limit);
    IPage<UserInfo> pageModel = userInfoService.listPage(pageParam, userInfoQuery);
    return R.ok().data("pageModel", pageModel);
  }

  @PutMapping("/lock/{id}/{status}")
  @ApiOperation("用户锁定与解锁")
  public R lock(@ApiParam(value = "用户id", required = true) @PathVariable Long id,
      @ApiParam(value = "锁定状态（0：锁定 1：解锁）", required = true) @PathVariable Integer status) {
    userInfoService.lock(id, status);
    return R.ok().message(status==1?"解锁成功":"锁定成功");
  }
}
